home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
C
/
serisamp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-30
|
5KB
|
175 lines
/* serial sample program v28 */
/****************************************************************
* *
* Copyright 1985, Commodore Amiga Inc. All rights reserved. *
* No part of this program may be reproduced, transmitted, *
* transcribed, stored in retrieval system, or translated into *
* any language or computer language, in any form or by any *
* means, electronic, mechanical, magnetic, optical, chemical, *
* manual or otherwise, without the prior written permission of *
* Commodore Amiga Incorporated, 983 University Avenue #D *
* Los Gatos, CA 95030 *
* *
****************************************************************/
#define SERPORTEVENTS
#include "exec/types.h"
#include "exec/nodes.h"
#include "exec/lists.h"
#include "exec/memory.h"
#include "exec/ports.h"
#include "exec/libraries.h"
#include "exec/devices.h"
#include "exec/tasks.h"
#include "exec/io.h"
#include "exec/interrupts.h"
#include "devices/timer.h"
#include "devices/inputevent.h"
#include "serial.h"
struct IOExtSer IORser;
struct MsgPort *port;
char buffer[100];
extern struct MsgPort *CreatePort();
main()
{
int error;
int actual;
unsigned char iof;
unsigned long cc;
unsigned long rbl;
unsigned long wbl;
unsigned long brk;
unsigned long baud;
unsigned char rwl;
unsigned char wwl;
unsigned char sf;
unsigned long t0;
unsigned long t1;
open:
/* OPEN the serial.device */
if ((error = OpenDevice (SERIALNAME, 0, &IORser, 0)) != 0) {
write ("bad news on Open\n",-1);
exit (error);
}
/* SET UP the read message port in the I/O request */
port = CreatePort (SERIALNAME,0);
IORser.IOSer.io_Message.mn_ReplyPort = port;
write ("\n\015opened ok\n\015", -1);
/* SET PARAMS for the serial.device
iof = 0x00;
cc = 0x00;
rbl = 4096;
wbl = 4096;
rwl = 0x08;
wwl = 0x08;
brk = 250000;
baud= 9600;
sf = 0x04;
t0 = 0x51515151;
t1 = 0x04040404;
if ((error = setparams (iof,cc,rbl,wbl,rwl,wwl,brk,baud,sf,t0,t1)) != 0) {
write ("bad news on setup \n\015", -1);
exit (error);
} */
write ("test of -1 length\n\015", -1);
write ("\n\015test of -1 length garbage till term7XXXXX", 43);
write ("\n\015test of -1 length garbage till term6XXXXX", 43);
actual = read (buffer,16);
write ("\n\015Buffer was :\n\015", -1);
write (buffer, actual);
write ("\n\015end\n\015", -1);
/* CLOSE the serial.device */
if ((error = CloseDevice (&IORser)) != 0) {
write ("bad news on Close\n",-1);
exit (error);
}
Debug (0);
}
setparams(is,ctl_char,rbuf_len,wbuf_len,rlen,wlen,brk,baud,sf,ta0,ta1)
unsigned char is;
unsigned long ctl_char;
unsigned long rbuf_len;
unsigned long wbuf_len;
unsigned char rlen;
unsigned char wlen;
unsigned long brk;
unsigned long baud;
unsigned char sf;
unsigned long ta0;
unsigned long ta1;
{
int error;
IORser.IOSer.io_Flags = is;
IORser.io_CtlChar = ctl_char;
IORser.io_ReadLen = rlen;
IORser.io_BrkTime = brk;
IORser.io_Baud = baud;
IORser.io_WriteLen = wlen;
IORser.io_StopBits = 0x01;
IORser.io_RBufLen = rbuf_len;
IORser.io_WBufLen = wbuf_len;
IORser.io_SerFlags = sf;
IORser.IOSer.io_Command = SDCMD_SETPARAMS;
IORser.io_TermArray.TermArray0 = ta0;
IORser.io_TermArray.TermArray1 = ta1;
if ((error = DoIO (&IORser)) != 0) {
write ("setp error\n", -1);
exit (1);
}
return (error);
}
read(data,length)
char *data;
ULONG length;
{
int error;
IORser.IOSer.io_Data = data;
IORser.IOSer.io_Length = length;
IORser.IOSer.io_Command = CMD_READ;
if ((error = DoIO (&IORser)) != 0) {
write ("read error\n", -1);
exit (1);
}
return (IORser.IOSer.io_Actual);
}
write(data,length)
char *data;
int length;
{
int error;
IORser.IOSer.io_Data = data;
IORser.IOSer.io_Length = length;
IORser.IOSer.io_Command = CMD_WRITE;
if ((error = DoIO (&IORser)) != 0) {
write ("serial.device write error\n", -1);
/* ShowIORequest (&IORser); */
exit (1);
}
return (IORser.IOSer.io_Actual);
}